const  install=(Vue,vm)=>{
	console.log(vm.$u)
	//登录接口
	let login=(reqParam={})=>vm.$u.post('/user/front-login', JSON.stringify(reqParam));
	
	//获取商品接口
	let products=()=>vm.$u.get('/items/all',{});
	
	let carousels=()=>vm.$u.get('/carousels',{});
	let cart={
		
		add:(uid,item={})=>vm.$u.post(`/cart/${uid}`,JSON.stringify(item)),
		get:uid=>vm.$u.get(`/cart/${uid}`),
		del:(uid,specid)=>vm.$u.put(`/cart/${uid}/${specid}`),
		clear:uid=>vm.$u.delete(`/cart/${uid}`)
		
	}
	
	let address={
		get:(uid)=>vm.$u.get(`/addresses/${uid}`,{}),
		add:(reqParam)=>vm.$u.post('/addresses',JSON.stringify(reqParam)),
		del:(addressId)=>vm.$u.delete(`/addresses/${addressId}`),
		put:(reqParam)=>vm.$u.put('/addresses',JSON.stringify(reqParam))
	}
	
	let orders={
		add:(reqParam)=>vm.$u.post('/orders',JSON.stringify(reqParam)),
		get:()=>vm.$u.get(`/orders/${uni.getStorageSync('userinfo').uid}`,{}),
		pay:(orderId)=>vm.$u.post(`/orders/pay/${orderId}`,{}),
		getOne:(orderId)=>vm.$u.get(`/orders/one/${orderId}`,{}),
		confirm:(orderId)=>vm.$u.put(`/orders/confirm/${orderId}`,{}),
		cancelOrder:(orderId)=>vm.$u.delete(`/orders/cancel/${orderId}`,{})
	}
	
	let user={
		update:(reqParam)=>vm.$u.put('/user',JSON.stringify(reqParam))
	}
	
	let comment={
		list:(productid)=>vm.$u.get(`/items/comments/${productid}`,{}),
		add:(reqParam,oid)=>vm.$u.post(`/items/comments/batch/${oid}`,JSON.stringify(reqParam))
	}
	
	
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
		vm.$u.api = {login, products,cart,carousels,address,user,orders,comment};
}

export default{
	install
}
